﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace baseClass.controls
{
    public partial class emWorkHistoryDetail : common.control.baseUserControl
    {
        private BindingSource myDataSource = null;
        public emWorkHistoryDetail()
        {
            InitializeComponent();
            SetMaxLength();
        }

        public void SetDataSource(System.Windows.Forms.BindingSource dataSrc)
        {
            this.myDataSource = dataSrc;
            data.baseDS.emWorkHistoryDataTable tbl = (data.baseDS.emWorkHistoryDataTable)dataSrc.DataSource;
            this.startDateEd.DataBindings.Clear();
            this.startDateEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.startDateColumn.ColumnName, true));
            
            this.endDateEd.DataBindings.Clear();
            this.endDateEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.enDateColumn.ColumnName, true));

            this.workPossitionCb.DataBindings.Clear();
            this.workPossitionCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataSrc, tbl.workPossitionColumn.ColumnName, true));

            this.workDescEd.DataBindings.Clear();
            this.workDescEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.workDescColumn.ColumnName, true));

            this.companyNameEd.DataBindings.Clear();
            this.companyNameEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.companyNameColumn.ColumnName, true));

            this.companyAddEd.DataBindings.Clear();
            this.companyAddEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.companyAddrColumn.ColumnName, true));

            this.comContactNameEd.DataBindings.Clear();
            this.comContactNameEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.comContactNameColumn.ColumnName, true));
            
            this.comContactEmailEd.DataBindings.Clear();
            this.comContactEmailEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.comContactEmailColumn.ColumnName, true));

            this.comContactPhoneEd.DataBindings.Clear();
            this.comContactPhoneEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.comContactPhoneColumn.ColumnName, true));

            this.comContactPossiotonCb.DataBindings.Clear();
            this.comContactPossiotonCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataSrc, tbl.comContactPositionColumn.ColumnName, true));
        }
        private void SetMaxLength()
        {
            data.baseDS.emWorkHistoryDataTable tbl = new data.baseDS.emWorkHistoryDataTable();
            companyNameEd.MaxLength = tbl.companyNameColumn.MaxLength;
            companyAddEd.MaxLength = tbl.companyAddrColumn.MaxLength;
            comContactNameEd.MaxLength = tbl.comContactNameColumn.MaxLength;
            comContactEmailEd.MaxLength = tbl.comContactEmailColumn.MaxLength;
            comContactPhoneEd.MaxLength = tbl.comContactPhoneColumn.MaxLength;
            workDescEd.MaxLength = tbl.workDescColumn.MaxLength;
        }
        public virtual void Init() 
        {
            workPossitionCb.LoadData();
            comContactPossiotonCb.LoadData();
        }

        public virtual bool CheckData()
        {
            if (this.myDataSource.Current == null) return true;
            bool retVal = true;
            ClearNotifyError();

            if (startDateEd.myDateTime == common.Consts.constNullDate)
            {
                NotifyError(startDateLbl);
                retVal = false;
            }
            if (endDateEd.myDateTime == common.Consts.constNullDate)
            {
                NotifyError(endDateLbl);
                retVal = false;
            }
            if (companyNameEd.Text.Trim() == "")
            {
                NotifyError(companyNameLbl);
                retVal = false;
            }
            if (companyAddEd.Text.Trim() == "")
            {
                NotifyError(companyAddLbl);
                retVal = false;
            }
            if (workPossitionCb.myValue == "")
            {
                NotifyError(workPossitionLbl);
                retVal = false;
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            if (myDataSource.Current == null) state = true; 
            startDateEd.ReadOnly = state;
            endDateEd.ReadOnly = state;
            workPossitionCb.Enabled = !state;
            companyGb.Enabled = !state;
            workDescEd.ReadOnly = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            startDateEd.Focus();
        }
    }
}
